#include"process.h"

#define NUM 101  //表示100%的进度
#define STYLE '#'






void FlushProcess(const char* tips,double total,double current)
{
  const char* lable = "|/-\\";
  static int count = 0;
  int size = strlen(lable);
  char buffer[NUM];
  memset(buffer,0,sizeof(buffer));
  double rate = 100 * current / total;
  int n = (int)rate;
  int i = 0;
  for(;i <=n ;i++)
  {
    buffer[i] = STYLE;
  }
  printf("[%s][%-100s][%.1lf%%][%c]\r",tips,buffer,rate,lable[(count++) % size]);
  fflush(stdout);
  if(rate >= 100)
  printf("\n");
}







void process_v1()
{
  char buffer[NUM];
  memset(buffer,0,sizeof(buffer));
  const char* lable = "|/-\\";
  int size = strlen(lable);
  int count = 0;
  while(count <= 100)
  {
    printf("[%-100s][%d%%][%c]\r",buffer,count,lable[count % size]);
    fflush(stdout);
    buffer[count++] = STYLE;
    usleep(50000);
  }
  printf("\n");
}
